package TestLocalDateTime;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

public class test {
    public static void main(String[] args) {
        test1();
        test2();
        test3();
        test4();
        test5();
    }
    public static void test1() {
        System.out.println("---------------test1()---------------");
        LocalDateTime localDateTime = LocalDateTime.now();//获得当前时间
        System.out.println("当前时间："+localDateTime);
        System.out.println(localDateTime.getYear());//今年年份
        System.out.println(localDateTime.getDayOfYear());//这一年的第几天
        System.out.println("------------");
        System.out.println(localDateTime.getMonth());//当前是那一月（英文输出）
        System.out.println(localDateTime.getMonthValue());//当前是那一月（阿拉伯数字输出）
        System.out.println(localDateTime.getDayOfMonth());//这一月的第几天
        System.out.println("------------");
        System.out.println(localDateTime.getDayOfWeek());//输出星期几（英文输出）
        System.out.println(localDateTime.getDayOfWeek().getValue());//输出星期几（阿拉伯数字输出）
        System.out.println("------------");
        System.out.println(localDateTime.getHour());//时
        System.out.println(localDateTime.getMinute());//分
        System.out.println(localDateTime.getSecond());//秒
    }
    public static void test2() {
        System.out.println("---------------test2()---------------");
        LocalDateTime localDateTime = LocalDateTime.of(2025,3,30,20, 0,2);//创建指定日期
        System.out.println("当前时间："+localDateTime);

    }
    public static void test3() {
        System.out.println("---------------test3()---------------");
        LocalDateTime localDateTime = LocalDateTime.parse("2025-03-30T20:00:02");//根据字符串创建日期，有严格的格式要求
        System.out.println("当前时间："+localDateTime);

    }
    public static void test4() {
        System.out.println("---------------test4()---------------");
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("增加一天后的日期："+localDateTime.plusDays(1));
        System.out.println("减少一天后的日期："+localDateTime.minusDays(1));
        System.out.println("------------");
        System.out.println("增加一周后的日期："+localDateTime.plusWeeks(1));
        System.out.println("减少一周后的日期："+localDateTime.minusWeeks(1));
        System.out.println("------------");
        System.out.println("增加一月后的日期："+localDateTime.plusMonths(1));
        System.out.println("减少一月后的日期："+localDateTime.minusMonths(1));
        System.out.println("------------");
        System.out.println("增加一年后的日期："+localDateTime.plusYears(1));
        System.out.println("减少一年后的日期："+localDateTime.minusYears(1));
    }
    public static void test5() {
        System.out.println("---------------test5()---------------");
        LocalDateTime currentDate = LocalDateTime.now();
        System.out.println("离当前最近的周一是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY)));
        System.out.println("离当前最近的周二是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY)));
        System.out.println("离当前最近的周三是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.WEDNESDAY)));
        System.out.println("离当前最近的周四是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.THURSDAY)));
        System.out.println("离当前最近的周五是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.FRIDAY)));
        System.out.println("离当前最近的周六是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SATURDAY)));
        System.out.println("离当前最近的周天是："+currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)));//今天就是周天
        System.out.println("------------");
        System.out.println("当周的周一是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)));
        System.out.println("当周的周二是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.TUESDAY)));
        System.out.println("当周的周三是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.WEDNESDAY)));
        System.out.println("当周的周四是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.THURSDAY)));
        System.out.println("当周的周五是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.FRIDAY)));
        System.out.println("当周的周六是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.SATURDAY)));
        System.out.println("当周的周天是："+currentDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)));
        System.out.println("------------");
        System.out.println("这个月的第一天："+currentDate.with(TemporalAdjusters.firstDayOfMonth()));
        System.out.println("这个月的最后一天："+currentDate.with(TemporalAdjusters.lastDayOfMonth()));
    }
}
